package hl.leco.colle.set;

/**
 * 一个测试类
 * @author Liu Huan
 */


public class Person {
    public String name;
    public int age;
	
	@Override
	public boolean equals(Object o) {
		//如果是内存中同一个对象
		if (this == o) return true;
		//如果对象为null 或者 两个对象不是一个类
		if (o == null || getClass() != o.getClass()) return false;
		
		Person person = (Person) o;
		//如果 age 不相等
		if (age != person.age) return false;
		//如果 name 不相等
		return name != null ? name.equals(person.name) : person.name == null;
	}
	@Override
	public int hashCode() {
		//计算公式 result = hash(name) * 31 + age
		int result = name != null ? name.hashCode() : 0;
		result = 31 * result + age;// 31*i == (i<<5)-i
		return result;
	}
	
	public Person(String name, int age) {
		this.name = name;
		this.age = age;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public int getAge() {
		return age;
	}
	
	public void setAge(int age) {
		this.age = age;
	}
	
	@Override
	public String toString() {
		return "Person{" +
				"name='" + name + '\'' +
				", age=" + age +
				'}';
	}
	
}
